/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.zbxsoft.utr.service.log  
 */
package com.apache.bid.service;

import java.lang.reflect.Method;

import org.apache.log4j.Logger;
import org.springframework.aop.MethodBeforeAdvice;

import com.apache.api.vo.ParamsVo;
import com.apache.cache.util.Validator;

/**
 * description:  竞价产品统一系统操作日志处理
 * @author Hou Dayu 创建时间：2016-2-23  
 * 
 */
public class WbdLogMessage implements MethodBeforeAdvice {

	private Logger log = Logger.getLogger(WbdLogMessage.class);

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see org.springframework.aop.AfterReturningAdvice#afterReturning(java.lang.Object, java.lang.reflect.Method, java.lang.Object[], java.lang.Object)  
	 */
	@SuppressWarnings("rawtypes")
	public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
		ParamsVo arguments = (ParamsVo) args[0];
		StringBuffer sb = new StringBuffer("wbd_log className=" + target.getClass().getName());
		sb.append(";method=" + method.getName());
		sb.append(";请求参数=");
		if (!Validator.isEmpty(arguments.getObj())) {
			sb.append("obj:[" + arguments.getObj() + "]");
		}
		if (!Validator.isEmpty(arguments.getParams())) {
			sb.append("params:[" + arguments.getObj() + "]");
		}
		if (Validator.isNotNull(arguments.getKey())) {
			sb.append("key:[" + arguments.getKey() + "]");
		}
		if (Validator.isNotNull(arguments.getMethodKey())) {
			sb.append("MethodKey:[" + arguments.getMethodKey() + "]");
		}
		if (Validator.isNotNull(arguments.getInfoId())) {
			sb.append("InfoId:[" + arguments.getInfoId() + "]");
		}
		log.info(sb.toString());
	}

	@SuppressWarnings("rawtypes")
	public void before(Method method, Object[] args, Object target) throws Throwable {
		ParamsVo arguments = (ParamsVo) args[0];
		StringBuffer sb = new StringBuffer("wbd_log className=" + target.getClass().getName());
		sb.append(";method=" + method.getName());
		sb.append(";请求参数=");
		if (!Validator.isEmpty(arguments.getObj())) {
			sb.append("obj:[" + arguments.getObj() + "]");
		}
		if (!Validator.isEmpty(arguments.getParams())) {
			sb.append("params:[" + arguments.getObj() + "]");
		}
		if (Validator.isNotNull(arguments.getKey())) {
			sb.append("key:[" + arguments.getKey() + "]");
		}
		if (Validator.isNotNull(arguments.getMethodKey())) {
			sb.append("MethodKey:[" + arguments.getMethodKey() + "]");
		}
		if (Validator.isNotNull(arguments.getInfoId())) {
			sb.append("InfoId:[" + arguments.getInfoId() + "]");
		}
		log.info(sb.toString());
	}
}
